@namespace MudBlazor
@using MudBlazor.Interfaces
@inherits MudComponentBase

<div @attributes="UserAttributes"
     class="@Classname"
     style="@Style"
     @onpointermove="@PointerMove"
     @onpointerenter="@PointerEnterAsync"
     @onpointerleave="@PointerLeaveAsync"
     @oncontextmenu="@((ActivationEvent == MouseEvent.RightClick ? ToggleMenuAsync : null)!)"
     @oncontextmenu:preventDefault="@(ActivationEvent == MouseEvent.RightClick)">
    @if (ActivatorHidden)
    {
        @* No need to render anything *@
    }
    else if (ActivatorContent != null)
    {
        <CascadingValue Value="@((IActivatable)this)" IsFixed="true">
            <div @onclick="ToggleMenuAsync" disabled="@Disabled" class="@ActivatorClassname">
                @ActivatorContent
            </div>
        </CascadingValue>
    }
    else if (string.IsNullOrEmpty(Icon))
    {
        <MudButton StartIcon="@StartIcon"
                   EndIcon="@EndIcon"
                   IconColor="@IconColor"
                   Color="@Color"
                   Size="@Size"
                   Variant="@Variant"
                   Disabled="@Disabled"
                   Ripple="@Ripple"
                   DropShadow="@DropShadow"
                   OnClick="@ToggleMenuAsync"
                   aria-label="@AriaLabel">
            @Label
        </MudButton>
    }
    else
    {
        <MudIconButton Variant="@Variant"
                       Icon="@Icon"
                       Color="@Color"
                       Size="@Size"
                       Disabled="@Disabled"
                       Ripple="@Ripple"
                       DropShadow="@DropShadow"
                       OnClick="@ToggleMenuAsync"
                       aria-label="@AriaLabel" />
    }

    @* The portal has to include the cascading values inside, because it's not able to teletransport the cascade *@
    <MudPopover Open="@Open"
                Class="@PopoverClassname"
                MaxHeight="@MaxHeight"
                AnchorOrigin="@(PositionAtCursor ? Origin.TopLeft : AnchorOrigin)"
                TransformOrigin="@TransformOrigin"
                RelativeWidth="@FullWidth"
                Style="@_popoverStyle"
                DropShadow="@DropShadow">
        <CascadingValue Value="@this">
            <MudList T="object"
                     Class="@ListClass"
                     Dense="@Dense"
                     @onpointermove="@PointerMove"
                     @onpointerenter="@PointerEnterAsync"
                     @onpointerleave="@PointerLeaveAsync">
                @ChildContent
            </MudList>
        </CascadingValue>
    </MudPopover>

    <MudOverlay Visible="Open && !_isTemporary" AutoClose OnClosed="CloseMenuAsync" LockScroll="LockScroll" />
</div>
